package com.hellpro.lolbox.home.presenter;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.hellpro.lolbox.bean.ZXZp;
import com.hellpro.lolbox.home.model.OnLoadXRecycleListener;
import com.hellpro.lolbox.home.model.ZXLoadXRecycleData;
import com.hellpro.lolbox.home.weight.ZXCommBFragment;

/**
 * Package_Name: com.hellpro.lolbox.home.presenter
 * Description :
 * author: HellPermanent
 * date:  2016/10/22 2:24
 * remarks：
 */
public class ZXRecycleBiz implements  IZXRecycle {

    private ZXCommBFragment fragment;
public  ZXRecycleBiz( ZXCommBFragment fragment){

    this.fragment =fragment;
}
    @Override
    public void loadJsonData(final Context context, String path) {
        ZXLoadXRecycleData zxLoadXRecycleData = new ZXLoadXRecycleData(context);
        zxLoadXRecycleData.loadRecycleData(path, new OnLoadXRecycleListener() {
            @Override
            public void success(final ZXZp zxZp) {


                MyHandler.getInstance().post(new Runnable() {
    @Override
    public void run() {

        fragment.setApaptData(zxZp);
if (fragment!= null) {
    fragment.hideProgress();
}
    }
});


            }

            @Override
            public void Failed() {

            }
        });
    }



    public   static class MyHandler extends Handler{


        private static volatile MyHandler instance;

        public  static  MyHandler getInstance (){
            if (null == instance){
                synchronized ( (MyHandler.class)){
                    if (null == instance){
                        instance = new MyHandler();
                    }
                }
            }
            return  instance;
        }
        private  MyHandler(){
            super(Looper.getMainLooper());
        }
    }
}
